package com.travel.server.manager.impl.dal;

import com.travel.common.util.CollectionUtil;
import com.travel.server.manager.dao.ContentInfoDao;
import com.travel.server.manager.model.ContentInfo;
import com.travel.server.manager.model.ContentInfoExample;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author: LiZhenhui
 * @Date: 2018/12/20 15:48
 * @Desc:
 */
@Component
@Slf4j
public class ContentDal {

    @Autowired
    private ContentInfoDao dao;

    public ContentInfo select(){
        ContentInfoExample example = new ContentInfoExample();
        example.setOrderByClause("id desc");
        return CollectionUtil.getFirst(dao.selectByExample(example));
    }

    public void insertOrUpdate(ContentInfo contentInfo){
        if(contentInfo.getId() == null){
            dao.insertSelective(contentInfo);
        }else{
            dao.updateByPrimaryKey(contentInfo);
        }
    }
}
